<?php

/**
 * 投诉建议
 */
class SuggestionController extends Controller_Base
{
    /**
     * 首页 - 列表
     */
    public function indexAction()
    {
        $getPage = $this->getRequest()->getQuery('page', 1);
        $limit = $this->getRequest()->getQuery('limit', 10);
        $page = intval(trim($getPage)) <= 0 ? 1 : intval(trim($getPage));
        $talkType = $this->getRequest()->getQuery('talkType', '');
        $callPhone = $this->getRequest()->getQuery('callPhone', '');

        // where
        $search = $pageQuery=[];
        $where = [];

        if($callPhone){//通话号码
            array_push($where,"callPhone = '{$callPhone}'");
        }

        if($talkType){//按照案件号查询
            array_push($where,"talkType = '{$talkType}'");
        }
        // count
        $pageQuery['limit'] = $limit;
        $pageQuery['talkType'] = $talkType;
        $pageQuery['callPhone'] = $callPhone;
        $search['where'] = $where;

        $countFields = ['count(*) as total'];
        $countArr = Module_Mediate_Suggestion::getInstance()->getAllBySearch($countFields, $search);
        $total_num = $countArr[0]['total'];
        // lis
        $list = [];

        if (intval($total_num) > 0) {
            $fields = [];
            $search['limit'] = $limit;
            $search['start'] = ($page - 1) * $limit;
            $search['order'] = 'addTime desc';
            $list = Module_Mediate_Suggestion::getInstance()->getAllBySearch($fields, $search);

        }

        //赋值调解部门
        $this->getMediationOrgan();

        //assign
        SmartyAdapter::assign('curPageNum', $page);
        SmartyAdapter::assign('totalnum', $total_num);
        SmartyAdapter::assign('totalPage', ceil($total_num / $limit));
        SmartyAdapter::assign('page_query', empty($pageQuery) ? '' : http_build_query($pageQuery));
        SmartyAdapter::assign('query', $pageQuery);
        SmartyAdapter::assign('list', $list);
    }

}
